package edu.luc.cs.backend;
//%TITLE   Duration class in days  (copyright 1997, Information Discplines, Inc.)
                                                              //package ididates;
 public class Days {
    int   value;              //  Internal representation in integer days
//%SPACE 3
//  Constructors and assignment
//  ---------------------------

 public Days(long x)  {value = (int) x;}
 public Days(      )  {this (0) ;}
 public Days(Days x)  {this (x.value);}

 public Days set (Days rs) {value = rs.value; return this;}
 public Days set (int  rs) {value = rs;       return this;}
//%SPACE 3
//  Conversion functions
//  --------------------

 public static String unitName() {return "day";} // English version

 public        String toString()
               {return value + " " + unitName() + (value == 1 ? "" : "s");}

 public        int    toInt() {return value;}
//%SPACE 3
//  ********* NOTE:
//    From here on Java demands repetition of code which in C++ would be
//    packaged for reuse.  Although this imposes major maintenance and
//    testing burdens, no practical alternative exists as of March, 1997.
//%SPACE 2
//  Relational operators  (implements "ordered")
//  --------------------

 public boolean equals     (Days rs) {return value == rs.value;}
 public boolean lessThan   (Days rs) {return value <  rs.value;}
 public boolean greaterThan(Days rs) {return value >  rs.value;}
 public boolean equals     (int  rs) {return value == rs;}
 public boolean lessThan   (int  rs) {return value <  rs;}
 public boolean greaterThan(int  rs) {return value >  rs;}
//%EJECT
//  Arithmetic operators  (implements "extent")
//  --------------------

 public Days minus()         {return new Days(this).minusSet();}

 public Days add  (Days rs)  {return new Days(this).addSet(rs);}
 public Days sub  (Days rs)  {return new Days(this).subSet(rs);}
 public Days add  (int  rs)  {return new Days(this).addSet(rs);}
 public Days sub  (int  rs)  {return new Days(this).subSet(rs);}
 public Date add  (Date rs)  {return           rs.add(this);}
 public Days mpy  (int  rs)  {return new Days(this).mpySet(rs);}
 public Days div  (int  rs)  {return new Days(this).divSet(rs);}
 public int  div  (Days rs)  {return value / rs.value;}
 public Days mod  (Days rs)  {return new Days(this).modSet(rs);}
 public Days mod  (int  rs)  {return new Days(this).modSet(rs);}

 public Days minusSet()       {value = -value;    return this;}

 public Days addSet(Days rs)  {value += rs.value; return this;}
 public Days subSet(Days rs)  {value -= rs.value; return this;}
 public Days addSet(int  rs)  {value += rs;       return this;}
 public Days subSet(int  rs)  {value -= rs;       return this;}
 public Days mpySet(int  rs)  {value *= rs;       return this;}
 public Days divSet(int  rs)  {value /= rs;       return this;}
 public Days modSet(Days rs)  {value %= rs.value; return this;}
 public Days modSet(int  rs)  {value %= rs;       return this;}
}
